/**
 * 
 */
package se.ricardo.gamesorgs.api.request;

/**
 * Class for storing the values entered by the user in the
 * JDialog add/edit form. <br>
 * Only used when editing the values of an existing game.
 * <br>
 * 
 * @author Ricardo Ocaña Leal
 *
 */
public class EditGameRequest extends AddGameRequest {
	private int id;
	private int previousListType;
	private boolean listTypeChange;
	
	/**
	 * Initialize variables with default values.
	 * */
	public EditGameRequest(
			int id,
			String title,
			String company,
			String system,
			String cart,
			String instructions,
			String box,
			String comment,
			int listType,
			int previousListType) {
		super(title, company, system, cart, instructions,
			box, comment, listType);
		
		this.id = id;
		this.previousListType = previousListType;
		
		setListTypeChanged(listType != previousListType);
	}
	
	/**
	 * Returns the database id of the game.
	 * <br>
	 * 
	 * @return
	 * An int with the id.
	 * */
	public int getId() {
		return id;
	}
	
	/**
	 * Returns a constant with the corresponding constant
	 * of the previous list type.
	 * <br>
	 * 
	 * @return
	 * An int with the previous list type constant.
	 * */
	public int getPreviousListType() {
		return previousListType;
	}
	
	/**
	 * Called to notify that the game has changed from one
	 * list type to another.<br>
	 * E.g. Wish list -> Collection
	 * <br>
	 * 
	 * @param
	 * b Boolean signaling whether the list type has changed.
	 * */
	private void setListTypeChanged(boolean b) {
		listTypeChange = b;
	}
	
	/**
	 * Called to check whether the game that is being edited
	 * has changed list type.
	 * <br>
	 * 
	 * @return
	 * Boolean signaling whether the list type has changed.
	 * */
	public boolean hasListTypeChanged() {
		return listTypeChange;
	}
	
	/**
	 * Creates a new AddGameRequest based on the values in this
	 * EditGameRequest, and returns it.
	 * <br>
	 * 
	 * @return
	 * A new {@link AddGameRequest} based on the current values.
	 * */
	public AddGameRequest toAddGameRequest() {
		return new AddGameRequest(
				getTitle(), getCompany(), getSystem(), getCart(),
				getInstructions(), getBox(), getComment(), getListType());
	}
}
